﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.project.dao.impl;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.ConstantDic;
import com.hh.bss.common.MapObjectRowMapper;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.project.dao.*;
import com.hh.bss.project.entity.*;
import com.hh.bss.project.service.*;
import com.hh.bss.project.vo.query.*;
import com.hh.bss.util.*;





import static com.hh.bss.util.ObjectUtils.*;

import org.springframework.stereotype.Repository;

@Repository
public class ContractJobCvJdDaoImpl extends BaseHibernateDao<ContractJobCvJd,java.lang.Integer>  implements ContractJobCvJdDao<ContractJobCvJd,java.lang.Integer>{

	public Class getEntityClass() {
		return ContractJobCvJd.class;
	}
	
	public Page findPage(ContractJobCvJdQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
        
		
		    Class[] os={ContractJobCvJdQuery.class};
    		Class property= org.springframework.beans.BeanUtils.findPropertyType(query.getField_type(), os);
        if (property!=null){
        	 if ("java.lang.String".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(),query.getQuery());
	    			
	    		}
	    		else if ("java.lang.Integer".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseInteger(query.getQuery(), 0));
	    			
	    		}
	    		else if ("java.lang.Double".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseDouble(query.getQuery(), 0));
	    		}
	    		else if ("java.util.Date".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), DateHelper.toDate(query.getQuery(), DateHelper.DEFAULT_DATE_FORMAT));
	    		}
        }	 
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuffer sql = new StringBuffer();		
		sql.append(" select * from ( ");		
		sql.append(" select a.id,a.cv_id cvId,a.type,a.sender_email senderEmail,a.reciever,a.subject,a.attachment,attachment2,b.cv_name cvName,a.job_id jobId,a.recieve_email recieveEmail,a.creator,a.create_dt createDt,a.modifier,a.modified_dt modifiedDt ");
		sql.append(" ,b.company,b.title,b.position,b.tel,b.mobile,c.status cvStatus  from contract_job_cv_jd a ");
		sql.append(" left join  cv b on a.cv_id=b.id and b.is_delete=0 ");		
		//sql.append(" left join  contract_job_cv_recom c on c.cv_id=a.cv_id and c.job_id = a.job_id ");
		sql.append(" left join contract_job_cv_recom c on c.cv_id=a.cv_id and c.job_id = a.job_id");
		sql.append(" ) info ");
		List values = new ArrayList();
		
		sql.append(" where 1=1 ");

		if (isNotEmpty(query.getType())){
			sql.append(" and info.type = ? ");
			values.add(query.getType());	
		}
		if (isNotEmpty(query.getCvId())){
			sql.append(" and info.cvId = ? ");
			values.add(query.getCvId());	
		}
		
		if (isNotEmpty(query.getJobId())){
			sql.append(" and info.jobId = ? ");
			values.add(query.getJobId());	
		}
		
		if (isNotEmpty(query.getCvName())){
			sql.append(" and info.cvName like ? ");
			values.add("%"+query.getCvName()+"%");	
		}
		if (isNotEmpty(query.getCreator())){
			sql.append(" and info.cvName = ? ");
			values.add(query.getCreator());	
		}
		sql.append(" order by info.createDt desc ");
		//return super.getJdbcDao().createPage(query, values, mapper, pageMaxSize, pageNumber)
		return super.getJdbcDao().createPage(sql.toString(),values.toArray(), new MapObjectRowMapper(), query.getPageSize(), query.getPageNumber()); 

	}
	

}
